const app = getApp();
import { zg99Request } from "/utils/requests";
Page({
  /**
   * 页面的初始数据
   */
  data: {
    showContact: true,
    suspendShow: true,
    showIcon: true,
    bgcolor: '',
    form: true,
    table: false,
    options: {
      s1: 'y',
      xiangmu: "sk",
      lx: "sk",
      selectNo: 'y',
    },
    yl: 1,
    gonghao: '无',
    fenxiao: '无',
    laiyuan: '河北省考职位查询',
    chaxunjg: '',
    cxlists: [],
    showIcon: !0,
    isShowAuth: !1,
    isShowCdNav: !1,
    onReachBottomNum: 0,
    listId: 1,
    lists: [{
      'title': '按个人条件查询',
      "zt": 'on'
    }, {
      'title': '按职位信息查询',
      "zt": ''
    }],
    nav: 1,
    zwid: 12,
    actid: 17122,
    name: '',
    title: '',
    cxlists: [], //存放比对过后的所有数据
    cxlists1: [], //存放临时的20条
    collectLists: [], //收藏列表--用于比对，输出当前收藏职位
    collectLen: 0,
    filed: {},
    file: [],
    str1: '',
    str2: '',
    str3: '',
    str4: '',
    str1Arr: [],
    str11: [],
    str2Arr: [],
    str22: [],
    str3Arr: [],
    str33: [],
    str4Arr: [],
    str44: [],
    cxFlag: false,
    zyLevel: 2,
    zylevel2: '',
    zylevel1: '',
    zylevel0: '',
    zydata: {},
    grdata: {
      tabnum: 1
    },
    grscdata: {
      flag: true,
      limits: 60,
      tabnum: 3
    }, //个人收藏条件
    qxdata: {
      flag: true,
      tabnum: 3
    }, //取消个人收藏条件
    xueliRst: '',
    xueweiRst: '',
    zldxRst: '',
    zzmmRst: '',
    sexRst: '',
    sfyjRst: '',
    xueliArr: [{
      id: "3_1",
      text: "不限"
    }, {
      id: "3_2",
      text: "高中"
    }, {
      id: "3_3",
      text: "中专"
    }, {
      id: "3_4",
      text: "专科"
    }, {
      id: "3_5",
      text: "本科"
    }, {
      id: "3_6",
      text: "研究生"
    }],
    bklx: [{
      id: "5_1",
      text: "综合岗"
    }, {
      id: "5_2",
      text: "教育岗"
    }, {
      id: "5_3",
      text: "医疗岗"
    }],
    xueweiArr: [{
      id: "6_1",
      text: "无"
    }, {
      id: "6_2",
      text: "学士"
    }, {
      id: "6_3",
      text: "硕士"
    }, {
      id: "6_4",
      text: "博士"
    }],
    sexArr: [{
      id: "7_1",
      text: "女"
    }, {
      id: "7_2",
      text: "男"
    }, {
      id: "7_2",
      text: "不限"
    }],
    zzmmArr: [{
      id: "8_1",
      text: "群众"
    }, {
      id: "8_2",
      text: "共青团员"
    }, {
      id: "8_3",
      text: "民盟盟员"
    }, {
      id: "8_4",
      text: "民进会员"
    }, {
      id: "8_5",
      text: "农工党"
    }, {
      id: "8_6",
      text: "民建会员"
    }, {
      id: "8_7",
      text: "中共党员"
    }, {
      id: "8_8",
      text: "不限"
    }],
    zldxArr: [{
      id: "9_1",
      text: "服务基层项目人员"
    }, {
      id: "9_2",
      text: "退役大学生士兵"
    }, {
      id: "9_3",
      text: "2年以上基层工作经历"
    }, {
      id: "9_4",
      text: "当地县乡事业编制人员"
    }, {
      id: "9_5",
      text: "不限"
    }],
    sfyjArr: [{
      id: "10_1",
      text: "是"
    }, {
      id: "10_2",
      text: "否"
    }, {
      id: "10_3",
      text: "不限"
    }],
    fypage: 1,
    zcpages: 1,
    bklxvalue: '',
    zhuanyeFlag: false,
    wx: '',
    myPhone: '',
    isSydw: false
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: async function (options) {
    this.setData(await app.methods.myPhone()); // 获取本地存储手机号
    if(!this.data.myPhone) {
      await app.methods.getPhoneNumber()
      this.setData({
        isShowAuth: !0
      })
  }
    xhs.showShareMenu({
      shareTypes: 'normal',
    })
    let links, jxOptions;
    if (options.scene) {
      options.scene = options.scene.replace(/%253D/g, ".");
      options.scene = options.scene.replace(/%2526/g, "-");
      jxOptions = await app.methods.getOPtions(options);
    }
    let id = options.scene ? jxOptions.id : options.id;
    options.id = id;
    links = await app.methods.getLink(id);
    options.fx = options.scene ? jxOptions.fx : options.fx;
    options.gh = options.scene ? jxOptions.gh : options.gh;
    options.actid = links.actid ? links.actid : '54132';
    options.yl = links.yl ? links.yl : '';
    options.lx = links.lx ? links.lx : '';
    options.xiangmu = links.xiangmu ? links.xiangmu : '';
    options.s1 = links.s1 ? links.s1 : 'y';
    if (options.actid == undefined) {
      this.setData({
        actid: '54132'
      })
    }
    if (options.yl != undefined) {
      if (options.yl.length > 0) {
        this.setData({
          yl: Number(options.yl)
        })
      }
    }
    if (options.lx != undefined) {
      if (options.lx.length > 0) {
        this.setData({
          isSydw: true
        })
      }
    }
    if (options.selectNo == undefined) {
      options.selectNo = 'y'
    }
    this.setData({
      options
    })
    this.setData(await app.methods.getIdentity(options)); // 获取个人身份信息
    if(this.data.getIdentity.crm) {
        options.wxh = this.data.getIdentity.crm
    } else {
        options.wxh = options.gh
    }
    this.setData(await app.methods.getWechat(options)); // 获取个人身份信息
    this.setData(await app.methods.guishudi(options)); // 获取归属地
    let fenbu = this.data.fenbu;
    let fenxiao = this.data.fenxiao;
    let getIdentity = this.data.getIdentity;
    getIdentity.fenbu = fenbu;
    getIdentity.fenxiao = fenxiao;
    getIdentity.zzname = this.data.zzname;
    getIdentity.zzid = this.data.zzid;
    getIdentity.erpdqm = this.data.erpdqm;
    this.setData({
      getIdentity: getIdentity
    })
    await this.levelOne();
    if(this.data.myPhone) {
      this.setData(await app.methods.getphonestatusCX(this.data.myPhone, this.data.options.actid, 'chaxun'))
      if(!this.data.user) {
        await this.getUser()
      }
    }
  },
  m_select_touch: async function (t) {
    var e = t.detail.selIndex,
      a = t.detail.stype,
      c = t.detail.level,
      f = t.detail.selectText;
    if (c == 1) {
      let data = {
        level: '2',
        'grfiled': 'str1',
        grtext: f == '不限' ? '' : f
      }
      let level2 = await this.level(data, c, 'str2', this.data.listId)
      a == '1' ? this.setData({
        str2Arr: level2,
        str3Arr: [],
        str4Arr: [],
        str1: t.detail.selectText
      }) : ''
    } else if (c == 2) {
      let data = {
        level: '3',
        grfiled: 'str2',
        grtext: f,
        onefiled: 'str1',
        onetext: a == '2' ? this.data.str1 : this.data.str11value
      }
      let level3 = [];
      level3 = a == '2' ? await this.level(data, c, 'str3', this.data.listId) : []
      a == '2' ? this.setData({
        str3Arr: level3,
        str4Arr: [],
        str2: t.detail.selectText
      }) : this.setData({
        str2: t.detail.selectText == "不限" ? '' : t.detail.selectText,
        str3: '',
        str4: ''
      })
    } else if (c == 3) {
      let data = {
        level: '4',
        'grfiled': 'str3',
        grtext: f,
        onefiled: 'str1',
        onetext: a == '3' ? this.data.str1 : this.data.str1,
        twofiled: 'str2',
        twotext: a == '3' ? this.data.str2 : this.data.str1,
        threefiled: 'str3',
        threetext: a == '3' ? this.data.str3 : ''
      }
      let level4 = await this.level(data, c, 'str4', this.data.listId)
      a == '3' ? this.setData({
        str4Arr: level4,
        str3: t.detail.selectText
      }) : this.setData({
        str3: '',
        str4: '',
        xueliArrvalue: f
      })
    } else if (c == 4) {
      a == '4' ? this.setData({
        str4: t.detail.selectText
      }) : ''
    } else if (c == 5) {
      this.setData({
        bklxvalue: f
      })
    } else if (c == 6) { //非级联--个人选项
      a == 'xueli' ? this.setData({
        xueliRst: t.detail.selectText == '不限' ? '' : t.detail.selectText
      }) : a == 'xuewei' ? this.setData({
        xueweiRst: t.detail.selectText == '无' ? '' : t.detail.selectText
      }) : a == 'zzmm' ? this.setData({
        zzmmRst: t.detail.selectText == '不限' ? '不限' : t.detail.selectText
      }) : a == 'sex' ? this.setData({
        sexRst: t.detail.selectText == '不限' ? '' : t.detail.selectText
      }) : a == 'sfyj' ? this.setData({
        sfyjRst: t.detail.selectText == '不限' ? '' : t.detail.selectText
      }) : this.setData({
        zldxRst: t.detail.selectText == '不限' ? '' : t.detail.selectText
      })
    }
  },
  //获取一级信息
  async levelOne() {
    return new Promise((resolve) => {
      zg99Request({
        url: '/index/chaxun/getlevel?actid=54132&callback=&',
        method: 'GET',
        dataType: 'jsonp',
        data: {
          level: '1',
          grfiled: '',
          grtext: '',
          time: Date.parse(new Date()) / 1e3
        },
      }).then(res => {
        let newStr = app.methods.getAPIReturn(res);
        if (newStr.status == 1) {
          var newArr = [];
          let lists = newStr.lists;
          lists = lists.sort(this.compare('str1'))
          for (var i = 0; i < lists.length; i++) {
            var newObj = {};
            newObj.id = '1_' + i;
            newObj.text = lists[i].str1;
            newArr.push(newObj)
          }
          this.setData({
            str1Arr: newArr,
            ms: newStr.lists.ms
          })
        }
        resolve()
      }).catch(err => {
        console.log(err)
        resolve()
      })
    })
  },
  // 排序
  compare(property) {
    return function (a, b) {
      var value1 = a[property];
      var value2 = b[property];
      return value2 - value1;
    }
  },
  // 选择专业
  m_selectSearch_touch: function (t) {
    var e = t.detail.selText;
    // var e='专科-农林牧渔-农业类-现代农业技术';
    let _index2 = e.lastIndexOf('-') + 1;
    let _index0 = e.indexOf('-') + 1;
    let _index1 = e.indexOf('-', _index0);
    let zy2 = e.substr(_index2, e.length);
    let zy1 = e.slice(_index1 + 1, _index2 - 1);
    let zy0 = e.slice(_index0, _index1);
    this.setData({
      zhuanye: zy2 == '不限' ? '' : zy2,
      zylevel2: zy2 == '不限' ? '' : zy2,
      zylevel1: zy1,
      zylevel0: zy0,
      zydata: {
        'zy0': zy0,
        'zy1': zy1,
        'zy2': zy2,
      },
      zhuanyeFlag: zy2 == '不限' || zy2 == '' ? false : true,
    });
  },
  // 切换“按个人条件查询”与“按职位信息查询”
  recoveryState: function (e) {
    if (e.currentTarget.id == 'on') {} else {
      if (e.currentTarget.dataset.num == 0) {
        this.setData({
          listId: 1,
          lists: [{
            'title': '按个人条件查询',
            "zt": 'on'
          }, {
            'title': '按职位信息查询',
            "zt": ''
          }]
        })
      } else if (e.currentTarget.dataset.num == 1) {
        this.setData({
          listId: 0,
          lists: [{
            'title': '按个人条件查询',
            "zt": ''
          }, {
            'title': '按职位信息查询',
            "zt": 'on'
          }],
          zhuanye: ''
        })
      }
    }
  },
  // 级联获取信息
  async level(data, level, levels, listId) {
    return new Promise((resolve) => {
      zg99Request({
        url: '/index/chaxun/getlevel?actid=54132&callback=&',
        method: 'GET',
        dataType: 'jsonp',
        data: {
          ...data,
          time: Date.parse(new Date()) / 1e3
        },
      }).then(res => {
        let newStr = app.methods.getAPIReturn(res);
        var newArr = [];
        if (listId == 1) {
          var newObj1 = {}
          newObj1.id = level + '_' + 0;
          newObj1.text = '不限';
          newArr.push(newObj1)
        }

        for (var i = (listId == 0 ? 0 : 1); i < (listId == 0 ? newStr.lists.length : newStr.lists.length + 1); i++) {
          var newObj = {};
          newObj.id = level + '_' + i;
          let j = (listId == 0 ? i : i - 1)
          newObj.text = newStr.lists[j][levels];
          newArr.push(newObj)
        }
        resolve(newArr)
      }).catch(err => {
        console.log(err)
        resolve()
      })
    })
  },

  // 按个人条件查询
  async clickfn() {
    if (!this.data.myPhone) {
      this.setData({
        isShowAuth: !0,
      })
      return false
    }
    if (!this.data.str1) {
      xhs.showToast({
        title: '请选择年份',
        icon: 'none',
        duration: 2000
      })
      return false
    }

    this.setData({
      fypage: 1,
      zyLevel: 2
    })
    let data = {
      str1: this.data.str1 == undefined ? '' : this.data.str1,
      str2: this.data.str2 == undefined ? '' : this.data.str2,
      str3: '',
      str4: '',
      xuewei: this.data.xueweiRst != undefined ? this.data.xueweiRst : '',
      xueli: this.data.xueliRst != undefined ? this.data.xueliRst : '',
      sex: this.data.sexRst != undefined ? this.data.sexRst : '',
      sfyj: this.data.sfyjRst != undefined ? this.data.sfyjRst : '',
      zldx: this.data.zldxRst != undefined ? this.data.zldxRst : '',
      zzmm: this.data.zzmmRst != undefined ? this.data.zzmmRst : '',
      zhuanye: this.data.zhuanye != undefined ? this.removeNumbersAndLetters(this.data.zhuanye) : '',
      limits: 20,
      page: this.data.fypage,
      tabnum: 1
    }
    let grscdata = {
      phone: this.data.myPhone,
      flag: true,
      limits: 60,
      tabnum: 3
    }
    this.setData({
      grdata: data,
      grscdata: grscdata,
      table: true,
      form: false,
      chaxunjg: 0,
      cxlists: [],
      allLists: [],
      onReachBottomlists: [],
      onReachBottomNum: this.data.onReachBottomNum + 1
    })
    await this.getUser()
    await this.chaxun(this.data.grdata)
    await this.chaxun2(this.data.grscdata)
    await this.match()
  },
  // 按职位信息查询
  async clickfn1() {
    if (!this.data.myPhone) {
      this.setData({
        isShowAuth: !0,
      })
      return false
    }
    if (!this.data.str1) {
      xhs.showToast({
        title: '请选择年份',
        icon: 'none',
        duration: 2000
      })
      return false
    }
    if (!this.data.str2) {
      xhs.showToast({
        title: '请选择行政隶属',
        icon: 'none',
        duration: 2000
      })
      return false
    }
    if (!this.data.str3) {
      this.setData({
        str3: ''
      })
    }
    if (!this.data.str4) {
      this.setData({
        str4: ''
      })
    }
    this.setData({
      fypage: 1
    })
    let data = {
      str1: this.data.str1 == undefined ? '' : this.data.str1,
      str2: this.data.str2 == undefined ? '' : this.data.str2,
      str3: this.data.str3 == undefined ? '' : this.data.str3,
      str4: this.data.str4 == undefined ? '' : this.data.str4,
      xuewei: '',
      xueli: '',
      sex: '',
      zldx: '',
      zzmm: '',
      zhuanye: '',
      limits: 20,
      page: this.data.fypage,
      tabnum: 1
    }
    let grscdata = {
      phone: this.data.myPhone,
      flag: true,
      limits: 60,
      tabnum: 3
    }
    this.setData({
      grdata: data,
      grscdata: grscdata,
      form: false,
      table: true,
      chaxunjg: 0,
      cxlists: [],
      allLists: [],
      onReachBottomlists: [],
      onReachBottomNum: this.data.onReachBottomNum + 1
    })
    await this.getUser()
    await this.chaxun(this.data.grdata)
    await this.chaxun2(this.data.grscdata)
    await this.match();
    this.setData({
      zhuanyeFlag: false
    })
  },
  // 按个人条件查询---专业--一级学科-专业大类--不限专业
  clickfn2: async function (t) {
    var e = t.currentTarget.dataset.zyjb;
    e == 'zy2' ? this.setData({
      zyLevel: 2
    }) : e == 'zy1' ? this.setData({
      zyLevel: 1
    }) : e == 'zy0' ? this.setData({
      zyLevel: 0
    }) : this.setData({
      zyLevel: 'bx'
    })
    if (e != 'zy00') {
      this.setData({
        onReachBottomNum: 0,
        zhuanye: this.data.zydata[e],
        ['grdata.zhuanye']: this.removeNumbersAndLetters(this.data.zydata[e]),
        ['grdata.page']: 0,
        page: 0,
        table: true,
        chaxunjg: 0,
        cxlists: [],
        allLists: [],
        onReachBottomlists: [],
        onReachBottomNum: this.data.onReachBottomNum + 1
      })
    } else {
      this.setData({
        onReachBottomNum: 0,
        zhuanye: '不限',
        ['grdata.zhuanye']: '不限',
        ['grdata.page']: 0,
        page: 0,
        table: true,
        chaxunjg: 0,
        cxlists: [],
        allLists: [],
        onReachBottomlists: [],
        onReachBottomNum: this.data.onReachBottomNum + 1
      })
    }
    let scdata = {
      phone: this.data.myPhone,
      limits: 60,
      tabnum: 3
    }
    this.setData({
      grscdata: scdata
    })
    await this.getUser()
    await this.chaxun(this.data.grdata)
    await this.chaxun2(this.data.grscdata)
    await this.match()
  },
  // 学员信息查询 
  async getUser() {
    app.globalData.laiyuan = `河北省考职位查询`
    if (!this.data.user) {
      await app.methods.registerCX(this.data.myPhone, this.data.options.actid, this.data.laiyuan, this.data.isSydw, this.data.getIdentity, this.data.bklxvalue, '', '', 'chaxun')
      this.setData({
        ['user.user.laiyuan']: '河北省考职位查询'
      })
    } else {
      let laiyuan = this.data.user.user.laiyuan;
      if (laiyuan.indexOf('河北省考职位查询') < 0) {
        await app.methods.updateuserCX(this.data.myPhone, this.data.options.actid, this.data.laiyuan, this.data.isSydw, this.data.getIdentity, this.data.bklxvalue, '', 'chaxun', '', this.data.user.user)
        this.setData({
          ['user.laiyuan']: '河北省考职位查询'
        })
      }
    }
  },
  // 查询数据
  async chaxun(data) {
    let e = this;
    return new Promise((resolve) => {
      zg99Request({
        url: '/index/chaxun/getfylist?actid=54132&callback=&',
        method: 'GET',
        dataType: 'jsonp',
        data: {
          ...data,
          time: Date.parse(new Date()) / 1e3
        },
      }).then(res => {
        let newStr = app.methods.getAPIReturn(res);
        if (newStr.msg != '暂无数据') {
          var lists = newStr.lists
          var newObj = [];
          if (lists.length >= 20) {
            for (var i = 0; i < 20; i++) {
              newObj.push(lists[i])
            }
          } else {
            newObj = lists
          }
          this.setData({
            chaxunjg: newStr.zcounts,
            zcpages: parseInt(newStr.zcounts / 20) + 1,
            cxlists1: this.data.cxlists.concat(newObj),
            allLists: lists,
            onReachBottomlists: lists,
            onReachBottomNum: this.data.onReachBottomNum + 1
          })
        } else {
          xhs.hideLoading()
          xhs.showToast({
            title: '未匹配到可报考岗位，请重新填写条件后查询!',
            icon: 'none',
            duration: 2000
          })

          this.setData({
            form: false,
            table: true,
            chaxunjg: 0,
            cxlists: [],
            cxlists1: [],
            allLists: [],
            onReachBottomlists: [],
            onReachBottomNum: this.data.onReachBottomNum
          })
        }
        resolve()
      }).catch(err => {
        console.log(err)
        resolve()
      })
    })
  },
  //匹配
  async match() {
    if (this.data.collectLists.length == 0) {
      //无需比较，直接输出
    } else {
      for (let i = 0; i < this.data.cxlists1.length; i++) {
        for (let j = 0; j < this.data.collectLists.length; j++) {
          if (this.data.cxlists1[i].str6 == this.data.collectLists[j].str6) {
            let a = this.data.cxlists1;
            let b = a[i];
            b.collect = true;
            this.setData({
              //cxlists1: a
              ['b.collect']: true
            })

          }
        }
      }

    }
    //计算完成之后渲染--最新条件不存在时，不需要重新渲染
    if (this.data.cxlists1.length != 0) {

      this.setData({
        form: false,
        table: true,
        cxlists: this.data.cxlists1,
        allLists: this.data.cxlists1,
        onReachBottomlists: this.data.cxlists1,
        onReachBottomNum: this.data.onReachBottomNum + 1
      })
      xhs.hideLoading()
      xhs.showToast({
        title: '数据查询成功!',
        icon: 'success',
        duration: 2000
      })
    }

  },
  // 查询数据-收藏列表-放到本地和当前职位信息比对
  async chaxun2(data) {
    return new Promise((resolve) => {
      zg99Request({
        url: '/index/chaxun/getfzinfo?actid=54132&callback=&',
        method: 'GET',
        dataType: 'jsonp',
        data: {
          ...data,
          time: Date.parse(new Date()) / 1e3
        },
      }).then(res => {
        let newStr = app.methods.getAPIReturn(res);
        if (newStr.msg != '暂无数据') {
          var newObj = newStr.lists
          this.setData({
            collectLists: newStr.lists,
            collectLen: newStr.lists.length
          })
        } else {
          this.setData({
            collectLists: [],
            collectLen: 0
          })
        }
        resolve()
      }).catch(err => {
        console.log(err)
        resolve()
      })
    })
  },
  // 重新检索
  changetj: function () {
    this.setData({
      table: false,
      form: true,
      allLists: "",
      cxlists: "",
      yearvalue: "",
      addressvalue: "",
      xueliArrvalue: "",
      zzmmvalue: "",
      zhuanye: "",
      str1: "",
      str2: "",
      str3: "",
      str4: "",
      ['zydata']: {},
      ['grdata']: {},
    })
  },
  // 触底刷新
  async onReachBottom() {
    if (this.data.table) {
      // 获取当前检索总页数---totleCont
      if (((this.data.chaxunjg) % 20) == 0) {
        var totleCont = parseInt(this.data.chaxunjg / 20)
      } else {
        var totleCont = parseInt(this.data.chaxunjg / 20) + 1
      }
      // 计算当前已经展示几屏--当前页码--nowCont
      if (this.data.cxlists.length % 20 == 0) {
        var nowCont = parseInt(this.data.cxlists.length / 20)
      } else {
        var nowCont = parseInt(this.data.cxlists.length / 20) + 1
      }
      // 判断是否已经全部加载完
      if ((((this.data.chaxunjg) % 20) == 0) && (totleCont == nowCont)) {
        xhs.showToast({
          title: '我是有底线哒',
          duration: 2000
        })
      } else if ((((this.data.chaxunjg) % 20) > 0) && (totleCont < (nowCont + 1))) {
        xhs.showToast({
          title: '我是有底线哒',
          duration: 2000
        })
      } else {
        // 注入新数据---重新走接口
        this.setData({
          fypage: this.data.fypage + 1,
          ['grdata.page']: this.data.fypage + 1
        })
        await this.chaxun(this.data.grdata)
        await this.chaxun2(this.data.grscdata)
        await this.match()
        // console.log(this.data.cxlists)
      }
    }
  },
  // 收藏
  collect: function (e) {
    if (this.data.myPhone != '') {
      if (this.data.collectLen >= 60) {
        xhs.showToast({
          title: '你收藏的职位太多了，先去精简一下吧',
          icon: 'success',
          duration: 2000
        })
        return false
      } else {
        xhs.showLoading({
          title: '收藏中！',
          icon: 'none',
          duration: 2000,
        })
        let str1, str2, str3, str4, zwid;
        let data = {
          str1: e.currentTarget.dataset.str1,
          str2: e.currentTarget.dataset.str2,
          str3: e.currentTarget.dataset.str3,
          str4: e.currentTarget.dataset.str4,
          str5: e.currentTarget.dataset.str5,
          str6: e.currentTarget.dataset.str6,
          str7: e.currentTarget.dataset.str7,
          str8: e.currentTarget.dataset.str8,
          str9: e.currentTarget.dataset.str9,
          str10: e.currentTarget.dataset.str10,
          str11: e.currentTarget.dataset.str11,
          zhuanye: e.currentTarget.dataset.zhuanye,
          phone: this.data.myPhone,
          flag: true,
          tabnum: 3
        }
        zg99Request({
          url: '/index/chaxun/writefz?actid=54132&callback=&',
          method: 'GET',
          dataType: 'jsonp',
          data: {
            ...data,
            time: Date.parse(new Date()) / 1e3
          },
        }).then(res => {
          let newStr = app.methods.getAPIReturn(res);
          if (newStr.status == 1) {
            this.setData({
              collectLen: this.data.collectLen + 1
            })
            var flag = {
              str6: e.currentTarget.dataset.str6
            };
            var index = (this.data.cxlists || []).findIndex((profile) => profile.str6 === flag.str6);
            let a = this.data.cxlists;
            let b = a[index];
            b.collect = true;
            this.setData({
              cxlists: a
            })
            xhs.hideLoading({})
            xhs.showToast({
              title: '添加收藏成功!',
              icon: 'success',
              duration: 1500
            })
          } else {
            console.log(newStr.mag)
          }
        }).catch(err => {
          console.log(err)
        })
      }
    } else {
      xhs.showToast({
        title: '请先注册',
        duration: 2000
      })
      if (app.globalData.PrivacyAuthorization) {
        this.setData({
          isShowAuth: !0,
          isPrivacyAuthorization: !0,
        })
      } else {
        this.setData({
          isShowAuth: !0,
          isPrivacyAuthorization: !1,
        })
      }
      return false
    }


  },
  // 去掉收藏信息
  async deleteCollect(e) {
    if (this.data.myPhone != '') {
      xhs.showLoading({
        title: '取消收藏中',
        icon: 'none',
        duration: 2000,
      })
      let str6 = e.currentTarget.dataset.str6;
      let sc_flag = e.currentTarget.dataset.collect;
      var flag = {
        str6: str6
      };
      var index = (this.data.collectLists || []).findIndex((profile) => profile.str6 === flag.str6);
      this.data.collectLists.splice(index, 1) //从当前收藏列表移除，无需渲染
      let data = {
        phone: this.data.myPhone,
        str6: str6,
        flag: true,
        tabnum: 3,
      }
      return new Promise((resolve) => {
        xhs.request({
          url: '/index/chaxun/getfzinfo?actid=54132&callback=&',
          method: 'GET',
          dataType: 'jsonp',
          data: {
            ...data,
            time: Date.parse(new Date()) / 1e3
          },
          success: ((res) => {
          }),
          fail: ((err) => {

          })
        }).then(res => {
          let newStr = app.methods.getAPIReturn(res);
          var qxdata = {
            flag: false,
            tabnum: 3,
            str6: str6,
            fzid: newStr.lists[0].id
          }
          this.setData({
            qxdata: qxdata
          })
          this.updatefz(qxdata)
          // 返回id
          resolve()
        }).catch(err => {
          console.log(err)
          resolve()
        })
      })
    } else {
      xhs.showToast({
        title: '请先注册',
        duration: 2000
      })
      if (app.globalData.PrivacyAuthorization) {
        this.setData({
          isShowAuth: !0,
          isPrivacyAuthorization: !0,
        })
      } else {
        this.setData({
          isShowAuth: !0,
          isPrivacyAuthorization: !1,
        })
      }
      return false
    }
  },
  // 更新辅助表信息
  updatefz(e) {
    zg99Request({
      url: '/index/chaxun/updatefz?actid=54132&callback=&',
      method: 'GET',
      dataType: 'jsonp',
      data: {
        ...this.data.qxdata,
        time: Date.parse(new Date()) / 1e3
      },
    }).then(res => {
      let newStr = app.methods.getAPIReturn(res);
      this.setData({
        collectLen: this.data.collectLen - 1
      })
      var flag = {
        str6: this.data.qxdata.str6
      };
      let index2 = (this.data.cxlists || []).findIndex((profile) => profile.str6 === flag.str6);
      let a = this.data.cxlists;
      let b = a[index2];
      b.collect = false;
      this.setData({
        cxlists: a
      })
      xhs.hideLoading()
      xhs.showToast({
        title: '取消收藏!',
        icon: 'success',
        duration: 2000
      })
      //提示取消成功
    }).catch(err => {
      console.log(err)
    })
  },
  //去往个人收藏
  goToMyCenter: function () {
    let e = this;
    var myData = {
      myPhone: this.data.myPhone,
      lx: this.data.options.lx,
      actid: this.data.options.actid,
      xiangmu: this.data.options.xiangmu,
      fx: this.data.options.fx,
      gh: this.data.options.gh,
      wxh: this.data.options.wxh,
    }
    xhs.navigateTo({
      url: './mycenter?data=' + JSON.stringify(myData),
    })
  },
  // 回到顶部
  toTop() {
    xhs.pageScrollTo({
      scrollTop: 0
    })
  },
  // 展开和收起
  toggle: function(e){
      const { index } = e.currentTarget.dataset;
      let { cxlists } = this.data;
      cxlists[index].toggle = !cxlists[index].toggle
      this.setData({
          cxlists
      })
  },
  // 监听手机号
  async watchBack(value) {
    if (value && value.myPhone) {
      this.setData({
        myPhone: value.myPhone
      })
    }
  },
  // 处理专业代码
  removeNumbersAndLetters(str) {
    return str.replace(/[a-zA-Z0-9]/g, '');
  },
  async user_login(e){
    if(typeof e.detail == 'boolean') {
      this.setData({
          isShowAuth: e.detail
      })
    } else {
      this.setData({
          myPhone: e.detail
      })
      this.setData(await app.methods.getphonestatusCX(this.data.myPhone, this.data.options.actid, 'chaxun'))
      if(!this.data.user) {
        await this.getUser()
      }
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成---从个人中心页面返回，
   */
  async onShow() {
    if (this.data.grdata.limits == 20) {
      this.setData({
        cxlists: [],
        collectLists: [],
        fypage: 1,
        ['grdata.page']: 1
      })
      await this.chaxun(this.data.grdata)
      await this.chaxun2(this.data.grscdata)
      await this.match()
    } else {

    }


  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    let { fx = 'hbwtb', gh = 'zcj37368', id } = this.data.options;
    console.log(`/packageB/skzwjs/skzwjs?id=${id}&fx=${fx}&gh=${gh}`)
    return {
      title: '河北省考职位检索',
      path: `/packageB/skzwjs/skzwjs?id=${id}&fx=${fx}&gh=${gh}`,
      imageUrl: 'https://statics.offcn.com/hb/pc/images/wxxcx/shareImg/skzwjs.jpg',
    }
  }
})